<?php

class Calendarmodel extends CI_Model {

    function __construct() {
        parent::__construct();
    }
	
	function getAllEventCalendar()
	{
		$sql = "SELECT * from absensi.calendar_event";
		$query = $this->db->query($sql);
		return $query->result();
	
	}
	
    function getbanyakjenisjabatan($jabatan_id = null, $jabatan_nama = null, $struk = null, $fu = null, $ft = null, $satker = null, $eselon = null) {
        $sql = " SELECT count(DISTINCT( a.jabatan_id)) as banyak
FROM public.m_spg_jabatan a
     left join m_spg_jabatan_kategori b on b.jabkat_id = a.jabkat_id
     left join m_spg_jabatan_rumpun c on c.rumpun_id = a.rumpun_id 
	 left join m_spg_satuan_kerja k on  k.satuan_kerja_id =  a.satuan_kerja_id  and  k.status = 1
                    where 1=1  ";

        $jabatan_nama = rawurldecode($jabatan_nama);
        if (isset($jabatan_nama) && $jabatan_nama != '-') {
            $sql .= " and  upper(a.jabatan_nama)  like '%'||upper('$jabatan_nama')||'%'  ";
        }

        if (isset($jabatan_id) && $jabatan_id != '-') {
            $sql .= " and  a.jabatan_id = '" . $jabatan_id . "'  ";
        }
        if (isset($eselon) && $eselon != '') {
            $sql .= " and   a.eselon_id in ($eselon)  ";
        }

        if ($struk == '2' || $fu == '4' || $ft == '3') {
            $sql .= "  and   cast( a.jabatan_jenis as char) in ('$struk','$fu','$ft')    ";
        }

//echo $sql;

        $query = $this->db->query($sql);
        return $query->row()->banyak;
    }


}
